﻿using System.Windows;
using System.Windows.Controls;
using DACU.Player;

namespace DACU.Tools
{
	class LvPlayListStyleSelector : StyleSelector
	{
		public override Style SelectStyle(object item, DependencyObject container)
		{
			var listView = ItemsControl.ItemsControlFromItemContainer(container) as ListView;
			if (listView != null)
			{
				int index = listView.ItemContainerGenerator.IndexFromContainer(container);
				var track = item as Track;
				if (listView.TryFindResource("CurrentPlaysRowEvent") is Style)
				{
					if (track != null && track.IsCurrentlyPlays)
						return listView.FindResource("CurrentPlaysRowEvent") as Style;
					return index % 2 == 0 ? listView.FindResource("NormalRowEvent") as Style : listView.FindResource("AlternativeRowEvent") as Style;
				}
				else
				{
					if (track != null && track.IsCurrentlyPlays)
						return Application.Current.Resources["CurrentPlaysRow"] as Style;
					return index % 2 == 0 ? Application.Current.Resources["NormalRow"] as Style : Application.Current.Resources["AlternativeRow"] as Style;
				}
			}
			return null;
		}
	}
}
